<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - gcov.info - curves/ParametersEncoder.cpp</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">curves</a> - ParametersEncoder.cpp<span style="font-size: 80%;"> (source / <a href="ParametersEncoder.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">gcov.info</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">205</td>
            <td class="headerCovTableEntry">238</td>
            <td class="headerCovTableEntryMed">86.1 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2014-06-30 01:17:31</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">15</td>
            <td class="headerCovTableEntry">17</td>
            <td class="headerCovTableEntryMed">88.2 %</td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : /** </a>
<span class="lineNum">       2 </span>            :  * File:   ParametersEncoder.cpp
<span class="lineNum">       3 </span>            :  * Author: nichole
<span class="lineNum">       4 </span>            :  * 
<span class="lineNum">       5 </span>            :  * Created on April 27, 2014
<span class="lineNum">       6 </span>            :  */
<span class="lineNum">       7 </span>            : #include &quot;ParametersEncoder.h&quot;
<span class="lineNum">       8 </span>            : 
<a name="9"><span class="lineNum">       9 </span>            : namespace gev {</a>
<span class="lineNum">      10 </span>            :     
<span class="lineNum">      11 </span><span class="lineCov">         18 :     ParametersEncoder::ParametersEncoder() {</span>
<a name="12"><span class="lineNum">      12 </span><span class="lineCov">         18 :     }</span></a>
<span class="lineNum">      13 </span>            :     
<span class="lineNum">      14 </span><span class="lineCov">         36 :     ParametersEncoder::~ParametersEncoder() {</span>
<span class="lineNum">      15 </span><span class="lineCov">         27 :     }</span>
<a name="16"><span class="lineNum">      16 </span>            :   </a>
<span class="lineNum">      17 </span>            :     // TODO:  improve the format of the output file one day
<span class="lineNum">      18 </span>            :     void ParametersEncoder::readFile(
<span class="lineNum">      19 </span><span class="lineNoCov">          0 :         vector&lt; unordered_set&lt;uint32_t&gt; &gt;&amp; outputEncodedVariables) {</span>
<span class="lineNum">      20 </span>            :         
<span class="lineNum">      21 </span><span class="lineNoCov">          0 :         string fileName = &quot;similar_curve_parameters.txt&quot;;</span>
<span class="lineNum">      22 </span>            :         
<span class="lineNum">      23 </span><span class="lineNoCov">          0 :         _readFile(fileName, outputEncodedVariables);</span>
<a name="24"><span class="lineNum">      24 </span><span class="lineNoCov">          0 :     }</span></a>
<span class="lineNum">      25 </span>            :     
<span class="lineNum">      26 </span><span class="lineCov">          3 :     void ParametersEncoder::_readFile(string fileName, </span>
<span class="lineNum">      27 </span><span class="lineCov">          3 :         vector&lt; unordered_set&lt;uint32_t&gt; &gt;&amp; outputEncodedVariables) {</span>
<span class="lineNum">      28 </span>            :         
<span class="lineNum">      29 </span><span class="lineCov">          3 :         string filePath = _getProjectTmpDirectoryPath();</span>
<span class="lineNum">      30 </span><span class="lineCov">          6 :         filePath = filePath.append(&quot;/&quot;);</span>
<span class="lineNum">      31 </span><span class="lineCov">          6 :         filePath = filePath.append(fileName);</span>
<span class="lineNum">      32 </span><span class="lineCov">          3 :         long buffSz = 10000*2048;</span>
<span class="lineNum">      33 </span><span class="lineCov">          3 :         char buf[buffSz];</span>
<span class="lineNum">      34 </span>            :         
<span class="lineNum">      35 </span><span class="lineCov">          3 :         long count = 0;</span>
<span class="lineNum">      36 </span>            :         
<span class="lineNum">      37 </span><span class="lineCov">          3 :         FILE *fl = NULL;</span>
<span class="lineNum">      38 </span>            :         try {
<span class="lineNum">      39 </span><span class="lineCov">          9 :             fl = fopen(filePath.c_str(), &quot;r&quot;);</span>
<span class="lineNum">      40 </span><span class="lineCov">          3 :             if (fl != NULL) {</span>
<span class="lineNum">      41 </span><span class="lineCov">          6 :                 bool doRead = !feof(fl);</span>
<span class="lineNum">      42 </span><span class="lineCov">       4311 :                 while (doRead) {</span>
<span class="lineNum">      43 </span>            :                     
<span class="lineNum">      44 </span><span class="lineCov">       8616 :                     char *line = fgets(buf, buffSz, fl);</span>
<span class="lineNum">      45 </span><span class="lineCov">       4308 :                     if (line == NULL) {</span>
<span class="lineNum">      46 </span><span class="lineCov">          3 :                         break;</span>
<span class="lineNum">      47 </span>            :                     }
<span class="lineNum">      48 </span>            :                                                             
<span class="lineNum">      49 </span><span class="lineCov">       4305 :                     long digit0 = 0;</span>
<span class="lineNum">      50 </span><span class="lineCov">       8610 :                     long digitn = strlen(line) - 1;</span>
<span class="lineNum">      51 </span><span class="lineCov">      25830 :                     while ((long)line[digit0] &lt; 33) {digit0++;}</span>
<span class="lineNum">      52 </span><span class="lineCov">      17218 :                     while ((long)line[digitn] &lt; 33) {digitn--;}</span>
<span class="lineNum">      53 </span>            :                                             
<span class="lineNum">      54 </span><span class="lineCov">       8610 :                     long nVars = _getNVarsOfAParameter(line, digit0, digitn);</span>
<span class="lineNum">      55 </span>            :                     
<span class="lineNum">      56 </span><span class="lineCov">       8610 :                     float *k = (float *)malloc(nVars * sizeof(float));</span>
<span class="lineNum">      57 </span><span class="lineCov">       8610 :                     float *sigma = (float *)malloc(nVars * sizeof(float));</span>
<span class="lineNum">      58 </span><span class="lineCov">       8610 :                     float *mu = (float *)malloc(nVars * sizeof(float));</span>
<span class="lineNum">      59 </span>            :                     
<span class="lineNum">      60 </span><span class="lineCov">       4305 :                     _parseLine(line, digit0, digitn, k, sigma, mu, nVars);</span>
<span class="lineNum">      61 </span>            :                     
<span class="lineNum">      62 </span><span class="lineCov">       8610 :                     unordered_set&lt;uint32_t&gt; similar;</span>
<span class="lineNum">      63 </span>            :                                         
<span class="lineNum">      64 </span><span class="lineCov">    1719090 :                     for (long i = 0; i &lt; nVars; i++) {</span>
<span class="lineNum">      65 </span>            :                         
<span class="lineNum">      66 </span><span class="lineCov">    2565720 :                         ParametersKey *key = new ParametersKey(k[i], sigma[i], </span>
<span class="lineNum">      67 </span>            :                             mu[i]);
<span class="lineNum">      68 </span>            :                         
<span class="lineNum">      69 </span>            :                         unordered_map&lt;gev::ParametersKey, uint32_t&gt;::const_iterator 
<span class="lineNum">      70 </span><span class="lineCov">    1710480 :                             iter = variableMap.find(*key);</span>
<span class="lineNum">      71 </span>            :                         
<span class="lineNum">      72 </span><span class="lineCov">     855240 :                         uint32_t varNum;</span>
<span class="lineNum">      73 </span><span class="lineCov">    2565720 :                         if (iter == variableMap.end()) {                            </span>
<span class="lineNum">      74 </span>            :                             
<span class="lineNum">      75 </span><span class="lineCov">    3591972 :                             varNum = variableMap.empty() ? 0 : variableMap.size();</span>
<span class="lineNum">      76 </span>            :                             
<span class="lineNum">      77 </span><span class="lineCov">    4310370 :                             variableMap.insert(</span>
<span class="lineNum">      78 </span><span class="lineCov">    1436790 :                                 make_pair&lt;gev::ParametersKey, uint32_t&gt;(*key, varNum));</span>
<span class="lineNum">      79 </span>            :    
<span class="lineNum">      80 </span><span class="lineCov">     718395 :                         } else {</span>
<span class="lineNum">      81 </span>            :                             
<span class="lineNum">      82 </span><span class="lineCov">     273690 :                             varNum = (*iter).second;</span>
<span class="lineNum">      83 </span>            :                         }
<span class="lineNum">      84 </span>            :                         
<span class="lineNum">      85 </span><span class="lineCov">     855240 :                         similar.insert(varNum);</span>
<span class="lineNum">      86 </span>            :                         
<span class="lineNum">      87 </span><span class="lineCov">    2565720 :                         delete key;</span>
<span class="lineNum">      88 </span><span class="lineCov">     855240 :                     }</span>
<span class="lineNum">      89 </span>            :                     
<span class="lineNum">      90 </span><span class="lineCov">       4305 :                     outputEncodedVariables.push_back(similar);</span>
<span class="lineNum">      91 </span>            :                     
<span class="lineNum">      92 </span><span class="lineCov">       4305 :                     free(k);</span>
<span class="lineNum">      93 </span><span class="lineCov">       4305 :                     free(sigma);</span>
<span class="lineNum">      94 </span><span class="lineCov">       4305 :                     free(mu);</span>
<span class="lineNum">      95 </span>            :                     
<span class="lineNum">      96 </span><span class="lineCov">       4305 :                     count++;</span>
<span class="lineNum">      97 </span><span class="lineCov">       8610 :                 }</span>
<span class="lineNum">      98 </span><span class="lineCov">          3 :             }</span>
<span class="lineNum">      99 </span><span class="lineCov">          3 :         } catch (std::exception e) {</span>
<span class="lineNum">     100 </span><span class="lineNoCov">          0 :             cerr &lt;&lt; &quot;Error: &quot; &lt;&lt; e.what() &lt;&lt; endl;</span>
<span class="lineNum">     101 </span><span class="lineNoCov">          0 :             if (fl != NULL) {</span>
<span class="lineNum">     102 </span><span class="lineNoCov">          0 :                 fclose(fl);</span>
<span class="lineNum">     103 </span><span class="lineNoCov">          0 :                 fl = NULL;</span>
<span class="lineNum">     104 </span><span class="lineNoCov">          0 :             }</span>
<span class="lineNum">     105 </span><span class="lineNoCov">          0 :             throw;</span>
<span class="lineNum">     106 </span>            :         }
<span class="lineNum">     107 </span><span class="lineCov">          3 :         if (fl != NULL) {</span>
<span class="lineNum">     108 </span><span class="lineCov">          3 :             fclose(fl);</span>
<span class="lineNum">     109 </span><span class="lineCov">          3 :             fl = NULL;</span>
<span class="lineNum">     110 </span><span class="lineCov">          3 :         }</span>
<a name="111"><span class="lineNum">     111 </span><span class="lineCov">          3 :     }</span></a>
<span class="lineNum">     112 </span>            :     
<span class="lineNum">     113 </span><span class="lineNoCov">          0 :     void ParametersEncoder::writeFile(vector&lt;uint32_t&gt;&amp; encodedCoverVariables) {</span>
<span class="lineNum">     114 </span>            :         
<span class="lineNum">     115 </span><span class="lineNoCov">          0 :         string fileName = &quot;gev_similarity_min_ranges-output.txt&quot;;</span>
<span class="lineNum">     116 </span>            :         
<span class="lineNum">     117 </span><span class="lineNoCov">          0 :         _writeFile(fileName, encodedCoverVariables);</span>
<a name="118"><span class="lineNum">     118 </span><span class="lineNoCov">          0 :     }</span></a>
<span class="lineNum">     119 </span>            :     
<span class="lineNum">     120 </span><span class="lineCov">          2 :     void ParametersEncoder::_writeFile(string fileName, </span>
<span class="lineNum">     121 </span><span class="lineCov">          2 :         vector&lt;uint32_t&gt;&amp; encodedCoverVariables) {</span>
<span class="lineNum">     122 </span>            :         
<span class="lineNum">     123 </span><span class="lineCov">          2 :         string filePath = _getProjectTmpDirectoryPath();</span>
<span class="lineNum">     124 </span><span class="lineCov">          4 :         filePath = filePath.append(&quot;/&quot;);</span>
<span class="lineNum">     125 </span><span class="lineCov">          4 :         filePath = filePath.append(fileName);</span>
<span class="lineNum">     126 </span>            :         
<span class="lineNum">     127 </span>            :         // create a reverse map to lookup vars
<span class="lineNum">     128 </span><span class="lineCov">          4 :         unordered_map&lt;uint32_t, gev::ParametersKey&gt; revLookupMap;</span>
<span class="lineNum">     129 </span>            :         
<span class="lineNum">     130 </span>            :         for (unordered_map&lt;gev::ParametersKey, uint32_t&gt;::const_iterator 
<span class="lineNum">     131 </span><span class="lineCov">    2394662 :             iter = variableMap.begin(); iter != variableMap.end(); ++iter) {</span>
<span class="lineNum">     132 </span>            :              
<span class="lineNum">     133 </span><span class="lineCov">    4310370 :             revLookupMap.insert( make_pair(iter-&gt;second, iter-&gt;first));</span>
<span class="lineNum">     134 </span><span class="lineCov">     478930 :         }</span>
<span class="lineNum">     135 </span>            :         
<span class="lineNum">     136 </span><span class="lineCov">          4 :         unsigned long len = encodedCoverVariables.size();</span>
<span class="lineNum">     137 </span>            :         
<span class="lineNum">     138 </span><span class="lineCov">          4 :         float *k = (float*)malloc(len * sizeof(float));</span>
<span class="lineNum">     139 </span><span class="lineCov">          4 :         float *sigma = (float*)malloc(len * sizeof(float));</span>
<span class="lineNum">     140 </span><span class="lineCov">          4 :         float *mu = (float*)malloc(len * sizeof(float));</span>
<span class="lineNum">     141 </span>            :         
<span class="lineNum">     142 </span><span class="lineCov">       2854 :         for (unsigned long i = 0; i &lt; len; i++) {</span>
<span class="lineNum">     143 </span>            :                 
<span class="lineNum">     144 </span><span class="lineCov">       2850 :             uint32_t varNum = encodedCoverVariables[i];</span>
<span class="lineNum">     145 </span>            : 
<span class="lineNum">     146 </span><span class="lineCov">       4275 :             ParametersKey key = revLookupMap.find(varNum)-&gt;second;</span>
<span class="lineNum">     147 </span>            : 
<span class="lineNum">     148 </span><span class="lineCov">       1425 :             float kv;</span>
<span class="lineNum">     149 </span><span class="lineCov">       1425 :             float sigmav;</span>
<span class="lineNum">     150 </span><span class="lineCov">       1425 :             float muv;</span>
<span class="lineNum">     151 </span>            : 
<span class="lineNum">     152 </span><span class="lineCov">       1425 :             key.decodeToParams(&amp;kv, &amp;sigmav, &amp;muv);</span>
<span class="lineNum">     153 </span>            : 
<span class="lineNum">     154 </span><span class="lineCov">       1425 :             k[i] = kv;</span>
<span class="lineNum">     155 </span><span class="lineCov">       1425 :             sigma[i] = sigmav;</span>
<span class="lineNum">     156 </span><span class="lineCov">       1425 :             mu[i] = muv;</span>
<span class="lineNum">     157 </span><span class="lineCov">       2850 :         }</span>
<span class="lineNum">     158 </span>            :         
<span class="lineNum">     159 </span>            :         //TODO:  sort by k, sigma, then mu
<span class="lineNum">     160 </span><span class="lineCov">          6 :         Sorter *sorter = new Sorter();</span>
<span class="lineNum">     161 </span><span class="lineCov">          2 :         sorter-&gt;sort(k, sigma, mu, len);</span>
<span class="lineNum">     162 </span><span class="lineCov">          6 :         delete sorter;</span>
<span class="lineNum">     163 </span>            :         
<span class="lineNum">     164 </span><span class="lineCov">          2 :         FILE *fl = NULL;</span>
<span class="lineNum">     165 </span>            :         try {
<span class="lineNum">     166 </span><span class="lineCov">          6 :             fl = fopen(filePath.c_str(), &quot;w&quot;);</span>
<span class="lineNum">     167 </span><span class="lineCov">          2 :             if (fl != NULL) {</span>
<span class="lineNum">     168 </span>            :                 
<span class="lineNum">     169 </span><span class="lineCov">          2 :                 fprintf(fl, &quot;#k             sigma          mu\n&quot;);</span>
<span class="lineNum">     170 </span><span class="lineCov">          2 :                 fflush(fl);</span>
<span class="lineNum">     171 </span>            :                 
<span class="lineNum">     172 </span><span class="lineCov">       2854 :                 for (unsigned long i = 0; i &lt; len; i++) {</span>
<span class="lineNum">     173 </span><span class="lineCov">       1425 :                     fprintf(fl, &quot;%e  %e  %e\n&quot;, k[i], sigma[i], mu[i]);</span>
<span class="lineNum">     174 </span><span class="lineCov">       1425 :                     if (i % 100 == 0) {</span>
<span class="lineNum">     175 </span><span class="lineCov">         16 :                         fflush(fl);</span>
<span class="lineNum">     176 </span><span class="lineCov">         16 :                     }</span>
<span class="lineNum">     177 </span><span class="lineCov">       1425 :                 }</span>
<span class="lineNum">     178 </span><span class="lineCov">          4 :                 printf(&quot;wrote to outfile: %s\n&quot;, filePath.c_str());</span>
<span class="lineNum">     179 </span><span class="lineCov">          2 :             } else {</span>
<span class="lineNum">     180 </span><span class="lineNoCov">          0 :                 printf(&quot;ERROR: unable to open outfile: %s\n&quot;, filePath.c_str());</span>
<span class="lineNum">     181 </span>            :             }
<span class="lineNum">     182 </span><span class="lineCov">          2 :         } catch (std::exception e) {</span>
<span class="lineNum">     183 </span><span class="lineNoCov">          0 :             cerr &lt;&lt; &quot;Error: &quot; &lt;&lt; e.what() &lt;&lt; endl;</span>
<span class="lineNum">     184 </span><span class="lineNoCov">          0 :             if (fl != NULL) {</span>
<span class="lineNum">     185 </span><span class="lineNoCov">          0 :                 fclose(fl);</span>
<span class="lineNum">     186 </span><span class="lineNoCov">          0 :                 fl = NULL;</span>
<span class="lineNum">     187 </span><span class="lineNoCov">          0 :             }</span>
<span class="lineNum">     188 </span><span class="lineNoCov">          0 :             free(k);</span>
<span class="lineNum">     189 </span><span class="lineNoCov">          0 :             free(sigma);</span>
<span class="lineNum">     190 </span><span class="lineNoCov">          0 :             free(mu);</span>
<span class="lineNum">     191 </span><span class="lineNoCov">          0 :             throw;</span>
<span class="lineNum">     192 </span>            :         }
<span class="lineNum">     193 </span><span class="lineCov">          2 :         if (fl != NULL) {</span>
<span class="lineNum">     194 </span><span class="lineCov">          2 :             fclose(fl);</span>
<span class="lineNum">     195 </span><span class="lineCov">          2 :             fl = NULL;</span>
<span class="lineNum">     196 </span><span class="lineCov">          2 :         }</span>
<span class="lineNum">     197 </span><span class="lineCov">          2 :         free(k);</span>
<span class="lineNum">     198 </span><span class="lineCov">          2 :         free(sigma);</span>
<span class="lineNum">     199 </span><span class="lineCov">          2 :         free(mu);</span>
<span class="lineNum">     200 </span>            :         
<span class="lineNum">     201 </span><span class="lineCov">          6 :         _copyOutputFileToMainProjectResources(fileName);</span>
<a name="202"><span class="lineNum">     202 </span><span class="lineCov">          4 :     }</span></a>
<span class="lineNum">     203 </span>            :     
<span class="lineNum">     204 </span>            :     string ParametersEncoder::_getProjectTmpDirectoryPath() {
<span class="lineNum">     205 </span>            :         
<span class="lineNum">     206 </span><span class="lineCov">          9 :         string cwd = _getCWD();</span>
<span class="lineNum">     207 </span>            :         
<span class="lineNum">     208 </span><span class="lineCov">         18 :         string srch = &quot;GEVSimilarity&quot;;</span>
<span class="lineNum">     209 </span>            :         
<span class="lineNum">     210 </span><span class="lineCov">         18 :         std::size_t found = cwd.find(srch);</span>
<span class="lineNum">     211 </span>            :         
<span class="lineNum">     212 </span><span class="lineCov">          9 :         if (found == std::string::npos) {</span>
<span class="lineNum">     213 </span><span class="lineNoCov">          0 :             fprintf(stderr, &quot;expecting current working directory is 'GEVSimilarity'\n&quot;);</span>
<span class="lineNum">     214 </span><span class="lineNoCov">          0 :             fflush(stderr);</span>
<span class="lineNum">     215 </span><span class="lineNoCov">          0 :             throw EINVAL;</span>
<span class="lineNum">     216 </span>            :         }
<span class="lineNum">     217 </span>            :         
<span class="lineNum">     218 </span><span class="lineCov">         18 :         string bDir = cwd.substr(0, found + srch.length());</span>
<span class="lineNum">     219 </span>            :         //printf(&quot;base directory = %s\n&quot;, bDir.c_str());
<span class="lineNum">     220 </span>            : 
<span class="lineNum">     221 </span>            :         // windows OS handles forward slash?  
<span class="lineNum">     222 </span>            :         
<span class="lineNum">     223 </span><span class="lineCov">         18 :         string dir = bDir.append(&quot;/tmpdata2&quot;);</span>
<span class="lineNum">     224 </span>            : 
<span class="lineNum">     225 </span><span class="lineCov">          9 :         return dir;</span>
<a name="226"><span class="lineNum">     226 </span><span class="lineCov">         36 :     }</span></a>
<span class="lineNum">     227 </span>            :     
<span class="lineNum">     228 </span>            :     string ParametersEncoder::_getMainProjectResourcesOutputDirectoryPath() {
<span class="lineNum">     229 </span>            :         
<span class="lineNum">     230 </span><span class="lineCov">          4 :         string cwd = _getCWD();</span>
<span class="lineNum">     231 </span>            :         
<span class="lineNum">     232 </span><span class="lineCov">          8 :         string srch = &quot;GEVSimilarity&quot;;</span>
<span class="lineNum">     233 </span>            :         
<span class="lineNum">     234 </span><span class="lineCov">          8 :         std::size_t found = cwd.find(srch);</span>
<span class="lineNum">     235 </span>            :         
<span class="lineNum">     236 </span><span class="lineCov">          4 :         if (found == std::string::npos) {</span>
<span class="lineNum">     237 </span><span class="lineNoCov">          0 :             fprintf(stderr, &quot;expecting current working directory is 'GEVSimilarity'\n&quot;);</span>
<span class="lineNum">     238 </span><span class="lineNoCov">          0 :             fflush(stderr);</span>
<span class="lineNum">     239 </span><span class="lineNoCov">          0 :             throw EINVAL;</span>
<span class="lineNum">     240 </span>            :         }
<span class="lineNum">     241 </span>            :         
<span class="lineNum">     242 </span><span class="lineCov">          8 :         string bDir = cwd.substr(0, found + srch.length());</span>
<span class="lineNum">     243 </span><span class="lineCov">          8 :         printf(&quot;base directory = %s\n&quot;, bDir.c_str());</span>
<span class="lineNum">     244 </span>            : 
<span class="lineNum">     245 </span>            :         // windows OS handles forward slashes?  
<span class="lineNum">     246 </span>            :         
<span class="lineNum">     247 </span><span class="lineCov">          8 :         string dir = bDir.append(&quot;/../../src/main/resources&quot;);</span>
<span class="lineNum">     248 </span>            : 
<span class="lineNum">     249 </span><span class="lineCov">          4 :         return dir;</span>
<a name="250"><span class="lineNum">     250 </span><span class="lineCov">         16 :     }</span></a>
<span class="lineNum">     251 </span>            :     
<span class="lineNum">     252 </span>            :     void ParametersEncoder::_copyOutputFileToMainProjectResources(
<span class="lineNum">     253 </span><span class="lineCov">          2 :     string fileName) {</span>
<span class="lineNum">     254 </span>            :         
<span class="lineNum">     255 </span><span class="lineCov">          2 :         string copyFilePath = _getProjectTmpDirectoryPath();</span>
<span class="lineNum">     256 </span><span class="lineCov">          4 :         copyFilePath = copyFilePath.append(&quot;/&quot;);</span>
<span class="lineNum">     257 </span><span class="lineCov">          4 :         copyFilePath = copyFilePath.append(fileName);</span>
<span class="lineNum">     258 </span>            :                 
<span class="lineNum">     259 </span><span class="lineCov">          2 :         string filePath = _getMainProjectResourcesOutputDirectoryPath();</span>
<span class="lineNum">     260 </span><span class="lineCov">          4 :         filePath = filePath.append(&quot;/&quot;);</span>
<span class="lineNum">     261 </span><span class="lineCov">          4 :         filePath = filePath.append(fileName);</span>
<span class="lineNum">     262 </span>            :                     
<span class="lineNum">     263 </span><span class="lineCov">          4 :         std::ifstream src(copyFilePath.c_str(), std::ios::binary);</span>
<span class="lineNum">     264 </span><span class="lineCov">          4 :         std::ofstream dest(filePath.c_str(), std::ios::binary);</span>
<span class="lineNum">     265 </span>            :         
<span class="lineNum">     266 </span><span class="lineCov">          4 :         dest &lt;&lt; src.rdbuf();</span>
<span class="lineNum">     267 </span>            :         
<span class="lineNum">     268 </span><span class="lineCov">          2 :         dest.flush();</span>
<span class="lineNum">     269 </span>            :         
<span class="lineNum">     270 </span><span class="lineCov">          2 :         src.close();</span>
<span class="lineNum">     271 </span><span class="lineCov">          2 :         dest.close();</span>
<span class="lineNum">     272 </span>            :         
<span class="lineNum">     273 </span><span class="lineCov">          4 :         printf(&quot;\ncopied to outfile: %s\n&quot;, filePath.c_str());</span>
<a name="274"><span class="lineNum">     274 </span><span class="lineCov">          8 :     }</span></a>
<span class="lineNum">     275 </span>            :     
<span class="lineNum">     276 </span>            :     string ParametersEncoder::_getCWD() {
<span class="lineNum">     277 </span>            :         
<span class="lineNum">     278 </span><span class="lineCov">         14 :         char *wdc = getcwd(NULL, 0);</span>
<span class="lineNum">     279 </span><span class="lineCov">         28 :         string cwd(wdc);</span>
<span class="lineNum">     280 </span><span class="lineCov">         14 :         free(wdc);</span>
<span class="lineNum">     281 </span>            :         
<span class="lineNum">     282 </span><span class="lineCov">         14 :         return cwd;</span>
<a name="283"><span class="lineNum">     283 </span><span class="lineCov">         28 :     }</span></a>
<span class="lineNum">     284 </span>            :     
<span class="lineNum">     285 </span><span class="lineCov">       4306 :     long ParametersEncoder::_getNVarsOfAParameter(const char *line, </span>
<span class="lineNum">     286 </span><span class="lineCov">       4306 :         const long digit0, const long digitn) {</span>
<span class="lineNum">     287 </span>            :         
<span class="lineNum">     288 </span><span class="lineCov">       4306 :         long nCommas = 0;</span>
<span class="lineNum">     289 </span>            :         
<span class="lineNum">     290 </span><span class="lineCov">       4306 :         bool foundK = false;</span>
<span class="lineNum">     291 </span>            :         
<span class="lineNum">     292 </span><span class="lineCov">   16957160 :         for (long i = digit0; i &lt; digitn; i++) {</span>
<span class="lineNum">     293 </span><span class="lineCov">    8478580 :             char c = line[i];</span>
<span class="lineNum">     294 </span><span class="lineCov">    8478580 :             if (foundK) {</span>
<span class="lineNum">     295 </span><span class="lineCov">    8474274 :                 if (c == ',') {</span>
<span class="lineNum">     296 </span><span class="lineCov">     851056 :                     nCommas++;</span>
<span class="lineNum">     297 </span><span class="lineCov">    8474274 :                 } else if (c == ' ') {</span>
<span class="lineNum">     298 </span><span class="lineCov">       4306 :                     break;</span>
<span class="lineNum">     299 </span>            :                 }
<span class="lineNum">     300 </span><span class="lineCov">    8474274 :             } else if (c == 'k') {</span>
<span class="lineNum">     301 </span><span class="lineCov">       4306 :                 foundK = true;</span>
<span class="lineNum">     302 </span><span class="lineCov">       4306 :             }</span>
<span class="lineNum">     303 </span><span class="lineCov">    8474274 :         }</span>
<span class="lineNum">     304 </span>            :         
<span class="lineNum">     305 </span><span class="lineCov">       4306 :         if (!foundK) {</span>
<span class="lineNum">     306 </span><span class="lineNoCov">          0 :             cerr &lt;&lt; &quot;Error reading line: &quot; &lt;&lt; string(line).c_str() &lt;&lt; endl;</span>
<span class="lineNum">     307 </span><span class="lineNoCov">          0 :             throw EINVAL;</span>
<span class="lineNum">     308 </span>            :         }
<span class="lineNum">     309 </span>            :         
<span class="lineNum">     310 </span><span class="lineCov">       4306 :         return (nCommas + 1);</span>
<a name="311"><span class="lineNum">     311 </span><span class="lineNoCov">          0 :     }</span></a>
<span class="lineNum">     312 </span>            :     
<span class="lineNum">     313 </span><span class="lineCov">       4305 :     void ParametersEncoder::_parseLine(const char *line, const long digit0, </span>
<span class="lineNum">     314 </span><span class="lineCov">       4305 :         const long digitn, float *k, float *sigma, float *mu, </span>
<span class="lineNum">     315 </span><span class="lineCov">       4305 :         const long nVars) {</span>
<span class="lineNum">     316 </span>            :         
<span class="lineNum">     317 </span><span class="lineCov">       4305 :         long nPos = digit0;</span>
<span class="lineNum">     318 </span>            :                     
<span class="lineNum">     319 </span><span class="lineCov">       4305 :         nPos = _parseLineForNextNVars(line, nPos, digitn, k, nVars);</span>
<span class="lineNum">     320 </span>            : 
<span class="lineNum">     321 </span><span class="lineCov">       4305 :         nPos = _parseLineForNextNVars(line, nPos, digitn, sigma, nVars);</span>
<span class="lineNum">     322 </span>            : 
<span class="lineNum">     323 </span><span class="lineCov">       4305 :         nPos = _parseLineForNextNVars(line, nPos, digitn, mu, nVars);            </span>
<a name="324"><span class="lineNum">     324 </span><span class="lineCov">       4305 :     }</span></a>
<span class="lineNum">     325 </span>            :     
<span class="lineNum">     326 </span><span class="lineCov">      12916 :     long ParametersEncoder::_parseLineForNextNVars(const char *line, </span>
<span class="lineNum">     327 </span><span class="lineCov">      12916 :         const long digit0, const long digitn, float *a, </span>
<span class="lineNum">     328 </span><span class="lineCov">      12916 :         const long nVars) {</span>
<span class="lineNum">     329 </span>            :         
<span class="lineNum">     330 </span><span class="lineCov">      12916 :         bool foundEq = false;</span>
<span class="lineNum">     331 </span><span class="lineCov">      12916 :         long sentinel = -1;</span>
<span class="lineNum">     332 </span><span class="lineCov">      12916 :         long n = 0;</span>
<span class="lineNum">     333 </span><span class="lineCov">      12916 :         long digitF0 = sentinel;</span>
<span class="lineNum">     334 </span><span class="lineCov">      12916 :         long i = sentinel;</span>
<span class="lineNum">     335 </span><span class="lineCov">   51405124 :         for (i = digit0; i &lt; digitn; i++) {</span>
<span class="lineNum">     336 </span><span class="lineCov">   25698257 :             char c = line[i];</span>
<span class="lineNum">     337 </span><span class="lineCov">   25698257 :             if (foundEq) {</span>
<span class="lineNum">     338 </span><span class="lineCov">   25633680 :                 if (c == ',') {</span>
<span class="lineNum">     339 </span>            :                     // parse float from digitF0 to digitFn
<span class="lineNum">     340 </span><span class="lineCov">    2552811 :                     a[n] = _convertToFloat(line, digitF0, i);</span>
<span class="lineNum">     341 </span><span class="lineCov">    2552811 :                     n++;</span>
<span class="lineNum">     342 </span><span class="lineCov">    2552811 :                     digitF0 = sentinel;</span>
<span class="lineNum">     343 </span><span class="lineCov">   25633680 :                 } else if (c == ' ') {</span>
<span class="lineNum">     344 </span><span class="lineCov">       8611 :                     break;</span>
<span class="lineNum">     345 </span><span class="lineCov">   23072258 :                 } else if (digitF0 == sentinel) {</span>
<span class="lineNum">     346 </span><span class="lineCov">    2565727 :                     digitF0 = i;</span>
<span class="lineNum">     347 </span><span class="lineCov">    2565727 :                 }</span>
<span class="lineNum">     348 </span><span class="lineCov">   25689646 :             } else if (c == '=') {</span>
<span class="lineNum">     349 </span><span class="lineCov">      12916 :                 foundEq = true;</span>
<span class="lineNum">     350 </span><span class="lineCov">      12916 :             }</span>
<span class="lineNum">     351 </span><span class="lineCov">   25689646 :         }</span>
<span class="lineNum">     352 </span>            :         
<span class="lineNum">     353 </span><span class="lineCov">      12916 :         a[n] = _convertToFloat(line, digitF0, i);</span>
<span class="lineNum">     354 </span><span class="lineCov">      12916 :         n++;</span>
<span class="lineNum">     355 </span>            :         
<span class="lineNum">     356 </span><span class="lineCov">      12916 :         return i;</span>
<a name="357"><span class="lineNum">     357 </span>            :     }</a>
<span class="lineNum">     358 </span>            :     
<span class="lineNum">     359 </span><span class="lineCov">    2565730 :     float ParametersEncoder::_convertToFloat(const char *line, </span>
<span class="lineNum">     360 </span><span class="lineCov">    2565730 :         const long digitBegin, const long digitEnd) {</span>
<span class="lineNum">     361 </span>            :         
<span class="lineNum">     362 </span><span class="lineCov">    2565730 :         long len = digitEnd - digitBegin + 1;</span>
<span class="lineNum">     363 </span>            :         
<span class="lineNum">     364 </span><span class="lineCov">    2565730 :         char buffer[len];</span>
<span class="lineNum">     365 </span>            :         
<span class="lineNum">     366 </span><span class="lineCov">   56407498 :         for (long i = 0; i &lt; len; i++) {</span>
<span class="lineNum">     367 </span><span class="lineCov">   25638019 :             buffer[i] = line[i + digitBegin];</span>
<span class="lineNum">     368 </span><span class="lineCov">   25638019 :         }</span>
<span class="lineNum">     369 </span>            :         
<span class="lineNum">     370 </span><span class="lineCov">    2565730 :         double d = atof(buffer);</span>
<span class="lineNum">     371 </span>            :         
<span class="lineNum">     372 </span><span class="lineCov">    2565730 :         return (float)d;</span>
<span class="lineNum">     373 </span><span class="lineCov">    2565730 :     }</span>
<span class="lineNum">     374 </span>            :     
<span class="lineNum">     375 </span>            : } // end namespace
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.11</a></td></tr>
  </table>
  <br>

</body>
</html>
